package com.tangding.aspect.god;

import java.util.Map;

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.beans.factory.annotation.Autowired;

import com.tangding.common.tools.ErrorConstants;
import com.tangding.hprose.api.server.command.Response;
import com.tangding.net.pool.BaseNettySessionPool;
import com.tangding.service.dao.role.PermissionRepository;
import com.tangding.service.dao.role.RoleRepository;
import com.tangding.service.dao.user.UserRepository;

/**
 * @description 
 *
 * @author Ranger
 * @version 2017年12月22日_下午5:38:35
 *
 */
public class GodAspect extends GodBase {
	
	@Autowired
	protected UserRepository userRepository;
	
	@Autowired
	protected RoleRepository roleRepository;
	
	@Autowired
	protected PermissionRepository permissionRepository;
	
	@Autowired
	protected BaseNettySessionPool pool;
	
	protected Map<String, Object> getUserInfo(ProceedingJoinPoint pjp) {
		Object[] args = pjp.getArgs();
		Object[] as = (Object[])(args[0]);
		@SuppressWarnings({ "rawtypes", "unchecked" })
		Map<String, Object> map = (Map)as[as.length - 1];
		return map;
	}
	
	protected Response doResponseSucc(Object data) {
		Response response = new Response();
		response.setCode(ErrorConstants.SUCC);
		response.setData(data);
		return response;
	}
	
	protected Response doResponseSucc() {
		Response response = new Response();
		response.setCode(ErrorConstants.SUCC);
		return response;
	}
	
	protected Response doResponseError() {
		Response response = new Response();
		response.setCode(ErrorConstants.FAIL);
		response.setMsg(ErrorConstants.getDesc(ErrorConstants.FAIL));
		return response;
	}
	
	protected Response doResponseError(int err) {
		Response response = new Response();
		response.setCode(err);
		response.setMsg(ErrorConstants.getDesc(err));
		return response;
	}
	
	protected Response doResponseError(int err, String msg) {
		Response response = new Response();
		response.setCode(err);
		response.setMsg(msg);
		return response;
	}
}
